//
//  MenuView.m
//  PopUpViewDemo
//
//  Created by king on 2021/3/31.
//  Copyright © 2021 Meng. All rights reserved.
//

#import "MenuView.h"
#import "MFFreedomButton.h"

@implementation MenuView

- (instancetype)initWithFrame:(CGRect)frame backImage:(NSString *)imageStr
{
    if (self = [super initWithFrame:frame]) {
        /**加载视图*/
        [self backGroundImage:frame backImage:imageStr];
    }
    return self;
}

#pragma mark 视图
- (void)backGroundImage:(CGRect)frame backImage:(NSString *)imageStr
{
    /**背景view*/
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    backImage.userInteractionEnabled = YES;
    backImage.image = [UIImage imageNamed:imageStr];
    [self addSubview:backImage];
    
    //顶部三角箭头高度 计算btn高度时需要减去
    int topSpacing = 5;
    //btn高度
    CGFloat btnHeight = (frame.size.height - topSpacing)/ 3;
    //btn宽度
    CGFloat btnWeight = frame.size.width;
    /**第一条线*/
    UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(60, topSpacing + btnHeight, btnWeight - 60, 0.5)];
    line1.backgroundColor = [UIColor whiteColor];
    [self addSubview:line1];
    /**第二条线*/
    UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(60, topSpacing + btnHeight * 2, btnWeight - 60, 0.5)];
    line2.backgroundColor = [UIColor whiteColor];
    [self addSubview:line2];
    
    for (int i = 0; i < 3; i++) {
        
        MFFreedomButton *addEventBtn = [[MFFreedomButton alloc] initWithFrame:CGRectMake(0, topSpacing + btnHeight*i, btnWeight, btnHeight)];
        [addEventBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [addEventBtn setTitle:@[@"添加事件",@"添加好友",@"发布动态"][i] forState:UIControlStateNormal];
        addEventBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        addEventBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [addEventBtn setImage:[UIImage imageNamed:@[@"icon_circle_hospital",@"icon_circle_hospital",@"icon_circle_hospital"][i]] forState:UIControlStateNormal];
        //btn中图片位置
        addEventBtn.imageRect = CGRectMake(20, (btnHeight - 20 ) / 2, 20,  20);
        //文字位置
        addEventBtn.labelRect = CGRectMake(60, 0, btnWeight - 60, btnHeight);
        addEventBtn.tag = i;
        [addEventBtn addTarget:self action:@selector(addEventBtnSelet:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:addEventBtn];
    }
}
- (void)addEventBtnSelet:(UIButton *)btn
{
    if (self.menuBlock) {
        self.menuBlock(btn.tag);
    }
}
@end
